package com.walkline.weibo.dao;

import java.util.Vector;

import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;

import com.walkline.util.Function;
import com.walkline.weibo.WeiboException;
import com.walkline.weibo.WeiboSDK;
import com.walkline.weibo.inf.Suggestion;
import com.walkline.weibo.inf.SuggestionWrapper;

public class WeiboSuggestionWrapper implements SuggestionWrapper
{
	private Vector _suggestions = new Vector();

	public WeiboSuggestionWrapper(WeiboSDK weibo, String stringObject) throws WeiboException
	{
		//super(weibo, jsonObject);

		JSONArray suggestions;
		try {
			suggestions = new JSONArray(stringObject);

			if (suggestions != null)
			{
				JSONObject suggestionObject;
				Suggestion suggestion;

				for (int i=0; i<suggestions.length(); i++)
				{
					try {
						suggestionObject = (JSONObject) suggestions.get(i);

						suggestion = new WeiboSuggestion(weibo, suggestionObject);
						if (suggestion != null) {_suggestions.addElement(suggestion);}
					} catch (JSONException e) {Function.errorDialog(e.toString());}
				}
			}
		} catch (JSONException e1) {}
	}

	public Vector getSuggestions() {return _suggestions;}
}